//
//  RightTableViewCell.swift
//  weather
//
//  Created by 陈思斌 on 24/8/17.
//  Copyright © 2017年 陈思斌. All rights reserved.
//

import UIKit

class RightTableViewCell: UITableViewCell {
    @IBOutlet weak var indicateImageView: UIImageView!

    @IBOutlet weak var titleLabel: UILabel!
    var controller:UIViewController?
    @IBOutlet weak var deleteImageView: UIImageView!
    override func awakeFromNib() {
        super.awakeFromNib()
        self.selectionStyle = .none
        self.backgroundColor = leftControllerAndRightControllerBgColor
        self.deleteImageView.isUserInteractionEnabled = true
        let tap = UITapGestureRecognizer(target: self, action: #selector(deleteCity))
        self.deleteImageView.addGestureRecognizer(tap)
        // Initialization code
    }
    func deleteCity(){
        let alert = UIAlertController(title: "删除提示", message: " 确定要删除\(self.titleLabel.text!)吗？", preferredStyle: .alert)
        let cancelAction = UIAlertAction(title: "取消", style: .cancel) { (action) in
            alert.dismiss(animated: true, completion: nil)
            
        }
        let okAction =  UIAlertAction(title: "确定", style: .default) { (action) in
            Helper.deleteCity(city: self.titleLabel.text!)
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: deleteLocationCityNotification), object: nil)
        }
        alert.addAction(cancelAction)
        alert.addAction(okAction)
        self.controller?.present(alert, animated: true, completion: nil)
    }
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesBegan(touches, with: event)
        self.backgroundColor = UIColor.gray
    }
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesEnded(touches, with: event)
        self.backgroundColor = leftControllerAndRightControllerBgColor
    }

    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
